package Arithmetic;

import java.text.NumberFormat;
import java.util.Random;
import java.util.Scanner;

/**
 * Created by Administrator on 2017/5/12.
 */
public class ResultTest {
    public static void main(String[] args) {
        Scanner Scan = new Scanner(System.in);
        Scanner Scan1 = new Scanner(System.in);
        NumberFormat fmt = NumberFormat.getPercentInstance();
        Random rnd = new Random();
        Questions Iq = new Questions();
        Calculator jdg = new Calculator();
        NifixToSuffix nts = new NifixToSuffix();

        int count;


        while(true) {
            int j = 0;
            System.out.print("请输入要生成的题目数：" );
            count = Scan.nextInt();

            for (int i = 0; i < count; i++) {
                //生成题目
                String expr = null;
                int a = rnd.nextInt(4);
                if (a == 0){
                   expr =  Iq.getAdd();
                }
                else if (a == 1){
                    expr = Iq.getSub();
                }
                else if (a == 2){
                    expr = Iq.getMulti();
                }
                else if (a == 3){
                    expr = Iq.getDiv();
                }
                System.out.print(expr + " = ");
                //输入结果

                String result = Scan1.nextLine();
                nts.conversion(expr);

                if (result.equals(jdg.evaluate(nts.getMessage()))){
                    System.out.println("正确！");
                    j++;
                }
                else
                    System.out.println("错误，正确答案为：" + jdg.evaluate(nts.getMessage()));
            }
            double accuracy = j/count;
            System.out.println("完成" + count + "道题目，正确率为" + fmt.format(accuracy));
            System.out.println("答对"+ j + "道题");
            String s1 = Scan.nextLine();
            System.out.print("是否继续生成题目？（y/n）:"  );
            String s2 = Scan.nextLine();
            if (s2.equalsIgnoreCase("n")){
                break;
            }

        }
    }
}
